<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>div垂直居中</title>
    <style>
    body{
        width:100%;
        height: 100%;
    }
    .demo{
        width:200px;
        height:100px;
        background-color: #ff0000;
        position: absolute;
        top:50%;
        left:50%;
        transform: translate(-50%,-50%);
     
    }
    </style>
</head>
<body>
    <div class="demo"></div>
</body>
</html>